using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;

public class UI_StatsSlot : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
    [SerializeField] private string statName;
    [SerializeField] private StatType statType;
    [SerializeField] private TextMeshProUGUI statValueText;
    [SerializeField] private TextMeshProUGUI statNameText;
    private UI ui;
    [TextArea]
    [SerializeField] private string statDescription;
    private void Awake()
    {
        ui = GetComponentInParent<UI>();
    }
    private void OnValidate()
    {
        gameObject.name = "Stat -" + statName;
        if (statNameText != null)
        {
            statNameText.text = statName;
        }
    }
    private void Update()
    {
        UpdateStatValueUI();

    }
    public void UpdateStatValueUI()
    {
        PlayerStats playerStats = PlayerManger.instance.player.GetComponent<PlayerStats>();
        if(playerStats!=null)
        {
            statValueText.text = playerStats.StatToModify(statType).GetValue().ToString();
        }
    }

    public void OnPointerEnter(PointerEventData eventData)
    {

        ui.statToolTip.ShowStatToolTip(statDescription);
       
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        ui.statToolTip.HideStatToolTip();
    }
}
